<?php

class ContentDAO extends My_DAO
{
	/** Table name */
    protected $_name    = 'content';
    
	public function buildQueryData($orderBy = "", $orderDirection = "",
									 $key = "", $field = "", $params = null)
	{
		$select = parent::buildQueryData($orderBy, $orderDirection,$key,$field);
		
		$categoryId = $params[0];
		if(!empty($categoryId))
		{
			$select->where('content.categoryId = '.$categoryId);
		}
		$langId = My_Translate::getLanguage();
		$select->where('category.languageId = '.$langId);
		
		$select->joinLeft('category', 
					'category.categoryId=content.categoryId', array('categoryName'))
				->joinLeft('user', 'userId = createdBy', array('userName'));
		
		return $select;
	}
	
	public function getPublish($catId)
	{
		$select = parent::buildQueryData();
		$select->where('content.status = 1');
		$select->where('content.categoryId = '.$catId);
//		$langId = My_Translate::getLanguage();
//		$select->where('category.languageId = '.$langId);
		$select->joinLeft('category', 
					'category.categoryId=content.categoryId', array('categoryName'));
		return $select;
	}
	
	public function getFirstPublish($catId)
	{
		$select = parent::buildQueryData();
		$select->where('content.status = 1');
		$select->where('content.categoryId = '.$catId);
//		$langId = My_Translate::getLanguage();
//		$select->where('category.languageId = '.$langId);
		$select->joinLeft('category', 
					'category.categoryId=content.categoryId', array('categoryName'));
		$select->limit(0,1);
		return $select;
	}
	
	
}

